<?php
require('functions/pageLoad.php');

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_GET['id'])){

// update FAQ

$lettingsQuery="UPDATE faqs SET question = '".$_POST['question']."', answer = '".$_POST['answer']."', tradesman = '".$_POST['tradesman']."', user = '".$_POST['user']."' WHERE id ='".$_GET['id']."'";
$lettingsResult=mysql_query( $lettingsQuery ) or die ("Error in query: $lettingsQuery . " . mysql_error());

$results = '<p style="color: #009900;">FAQ successfully updated!</p>';

}

if(isset($_GET['id'])){

// load FAQ edit form

$lettingsQuery="SELECT id, question, answer, tradesman, user FROM faqs WHERE id = '".$_GET['id']."'";
$lettingsResult=mysql_query( $lettingsQuery ) or die ("Error in query: $lettingsQuery . " . mysql_error());
$lettingsArr=mysql_fetch_assoc($lettingsResult);

$results = (strpos($_SERVER['HTTP_REFERER'], 'add_faqs.php') !== false) ? '<p style="color: #009900;">FAQ successfully added!</p>' : $results ;

$content='';
}

require('includes/meta.php');
require('includes/header.php');
require('includes/leftColumn.php');
?><div id="middleColumn"><div id="content">

<h2><?php echo $lettingsArr['question']; ?></h2>

<?php echo $results; ?>

<form method="post" action="?id=<?php echo $_GET['id']; ?>" id="adminFAQForm" style="float: left; padding-top: 10px;">

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="tradesman">Tradesman:</label></div>
<div class="formInputRight"><input type="checkbox" id="tradesman" name="tradesman" value="1"<?php if($lettingsArr['tradesman'] == '1'){ echo ' checked="checked"'; } ?> /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="user">User:</label></div>
<div class="formInputRight"><input type="checkbox" id="user" name="user" value="1"<?php if($lettingsArr['user'] == '1'){ echo ' checked="checked"'; } ?> /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="question">Question:</label></div>
<div class="formInputRight"><input type="text" id="question" name="question" style="width: 300px;" value="<?php echo $lettingsArr['question']; ?>" /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft">Answer:</div>
<div class="formInputRight"><textarea name="answer" rows="7" cols="35"><?php echo $lettingsArr['answer']; ?></textarea></div>
</div>


<div class="formInputLeft"><a onclick="return validateFAQForm();" class="button" style="color: #ffffff;">Edit FAQ</a></div><div class="formInputRight" id="jsErr" style="padding-top: 10px; color: #ff0000;"></div>

</form>

</div>
</div>
</div>

<?php
require('includes/footer.php');
?>